const { Controller } = require('egg');

class ShopController extends Controller {
    async getItem() {
    const { ctx } = this;
    const { item } = ctx.request.body
    const data = await ctx.app.mysql.get('shop',{
        ...item
    })
    ctx.body = {
        data,
        message:'获取成功'
    };
  }

    async insertItem() {
    const { ctx } = this;
    const { item } = ctx.request.body
    const data = await ctx.app.mysql.insert('shop',{
        ...item
    })
    ctx.body = {
        data,
        message:'新增成功'
    };
  }

  async updateItem() {
    const { ctx } = this;
    const { id } = ctx.request.body
    const data = await ctx.app.mysql.update('shop',{
        id
    })
    ctx.body = {
        data,
        message:'编辑成功'
    };
  }
  async deleteItem() {
    const { ctx } = this;
    const { id } = ctx.query
    const data = await ctx.app.mysql.delete('shop',{
        id
    })
    ctx.body = {
        data,
        message:'删除成功'
    };
  }

  async ssItem() {
    const { ctx } = this;
    const { val } = ctx.request.body
    // const data = await ctx.app.mysql.get('shop',{
    //     id
    // })
    const data = await ctx.app.mysql(`SELECT * FROM shop WHERE %${val}%`)
    ctx.body = {
        data,
        message:'搜索成功'
    };
  }
}

module.exports = ShopController;
